/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.meter.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.meter.AMeterInput;
import com.thor.palmmall.spi.meter.SMeterInput;
import com.thor.palmmall.spi.meter.SMeterInputState;

/**
 * @author wolv
 *
 */
public class SMeterInputConverter implements Converter<AMeterInput, SMeterInput> {

  public static SMeterInputConverter getInstance() {
    if (instance == null)
      instance = new SMeterInputConverter();
    return instance;
  }

  private static SMeterInputConverter instance;

  private SMeterInputConverter() {
  }

  @Override
  public SMeterInput convert(AMeterInput source) {
    if (source == null)
      return null;

    SMeterInput target = new SMeterInput();
    target.setMeter(UCN.newInstance(source.getMeter()));
    target.setPosition(source.getPosition());
    target.setRemark(source.getRemark());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setUuid(source.getUuid());
    target.setPeriodValues(
        SMeterInputPeriodValueConverter.getInstance().convert(source.getPeriodValues()));
    target.setBillNumber(source.getBillNumber());
    if (source.getBizState() != null)
      target.setBizState(SMeterInputState.valueOf(source.getBizState().name()));
    return target;
  }

}
